'use strict';
const db = uniCloud.database();
const dbCmd = db.command;
const $ = dbCmd.aggregate;
exports.main = async (event, context) => {
	//event为客户端上传的参数
	// console.log('event : ', event)
	// const collection = db.collection('memory,uni-id-users').where('user_id._id == "609e88269efd500001bc702a"').field('user_id{nickName,mobile}')
	// .get().then(res=>{
	// 	console.log(res)
	// 	return res
	// }).catch(err=>{
	// 	console.log(err)
	// })
	// // const res = await collection.limit(10).get()
	// //返回数据给客户端
	let page =event.page || 1
	let pageCount=event.pageCount || 10
	let skipC= event.skipC ? event.skipC : (page - 1)*pageCount;
	let res =await db.collection('memory-video').aggregate().skip(skipC).limit(pageCount).lookup(
		{
			from:'uni-id-users',
			localField:'user_id',
			foreignField:'_id',
			as:'user_id'
		}	
	)
	.sort(
		{
			publish_date:-1
		}
	)
	.project({
		// memoryWatchList:1,
		title:1,
		video:1,
		imgList:1,
		classfy:1,
		classfyLabel:1,
		canComment:1,
		memoryDate:1,
		publish_date:1,
		commentTotal:1,
		duration:1,
		'user_id':{
			nickName: 1,
			sex: 1,
			mobile:1,
			avatar:1
		  },
		
	}).end()
	
	// console.log(res,'res')
	return res
};
